import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "about_orm.settings")

import django

django.setup()
from app01 import models

from django.db.models import F, Q

ret = models.Book.objects.filter(kucun__lt=50)
ret = models.Book.objects.filter(sale__gt=F('kucun'))

# 将符合条件的数据重置，重置值为50
ret = models.Book.objects.filter(id__lte=50).update(sale=50)
# 将原本的值乘2
ret = models.Book.objects.filter(id__lte=50).update(sale=F('sale') * 2 + 13)

# exclude 条件筛选，取反操作
# (Q的使用)
# | 或
# & 与
# ~ 非
ret = models.Book.objects.filter(id__lt=3, id__gt=5)
ret = models.Book.objects.exclude(id__lt=3, id__gt=5)
ret = models.Book.objects.filter(Q(id__lt=3) | Q(id__gt=5))  # 小于3或者大于5

print(ret)
